package com.gitee.deeround.jdbchelper.core.impl;

import com.gitee.deeround.jdbchelper.core.DbActionExt;
import com.gitee.deeround.jdbchelper.core.Dialect;
import com.gitee.deeround.jdbchelper.core.DialectHelper;
import org.springframework.jdbc.core.JdbcTemplate;

public class DbActionExtImpl extends BaseDbAction implements DbActionExt {

    private final JdbcTemplate jdbcTemplate;

    public DbActionExtImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public void mergeInto(String tableName, String newData, String on, String insertSql, String updateSql) {
        Dialect dialect = DialectHelper.getDialect(jdbcTemplate);
        String sql = dialect.mergeInto(tableName, newData, on, insertSql, updateSql);
        jdbcTemplate.update(sql);
    }
}
